大家好~
今天來實作下圖架構的簡單版吧!


選擇一個 Dialogflow 的 Agent,
先點擊齒輪,
再點擊 Project ID,
會導向到 Google Cloud Platform。

點擊建立憑證。
建立一個服務帳戶。

輸入服務帳戶名稱。

選擇角色 Dialogflow 服務代理人 。

點擊完成建立服務帳戶。

點擊剛剛建立的服務帳號。

金鑰
新增金鑰
建立新的金鑰

選擇 JSON,
點擊建立下載金鑰。
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Google\Cloud\Dialogflow\V2\TextInput;
use Google\Cloud\Dialogflow\V2\QueryInput;
use Google\Cloud\Dialogflow\V2\SessionsClient;
public function test(Request $request)
{
$textInput = new TextInput();
$textInput->setLanguageCode('zh-TW')
->setText($request->text);
$queryInput = new QueryInput();
$queryInput->setText($textInput);
$sessionsClient = new SessionsClient([
'credentials' => env('GOOGLE_APPLICATION_CREDENTIALS')
]);
$session = $sessionsClient::sessionName(
env('DIALOGFLOW_PROJECT_ID'), uniqid()
);
$detectIntentResponse = $sessionsClient->detectIntent($session, $queryInput);
$queryResult = $detectIntentResponse->getQueryResult();
$fulfillmentText = $queryResult->getFulfillmentText();
return $fulfillmentText;
}
env 介紹:
就用上次 Day27 做的 Intent 做測試吧!



成功~
那麼今天先這樣啦~
若文章有任何問題,
還請大家不吝賜教!
大家明天見!